import { getItem, setItem } from '@/utils/storage'

const state = {
  questionList: getItem('questionList') || [],
}
const mutations = {
  SET_QUESTION(state, quest) {
    console.log(quest)
    if (state.questionList.length > 0) {
      // 判断是否重复
      const index = state.questionList.findIndex((item) => item.questionId === quest.questionId)
      if (index !== -1) {
        // 如果找到对应的题目，修改状态
        state.questionList[index].isLocked = quest.isLocked
      } else {
        // 如果是该题目是第一次添加
        state.questionList.push(quest)
      }
    } else {
      // question中的数据是空的，直接添加
      state.questionList.push(quest)
      console.log(state.questionList, 'questionList')
    }
    setItem('questionList', state.questionList)
  },
}
const actions = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
